package StudyCode.summary.zipfile;

import java.io.*;
import java.util.zip.GZIPInputStream;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class UngzipGzippedFileToNormalFile {
	public static void unzip(File gzippedFile, File ungzippedFile)
			throws IOException {
		GZIPInputStream gis = null;
		FileOutputStream fos = null;
		try {
			gis = new GZIPInputStream(new FileInputStream(gzippedFile));
			fos = new FileOutputStream(ungzippedFile);
			byte[] buffer = new byte[1024];
			int len = -1;
			while ((len = gis.read(buffer)) != -1) {
				fos.write(buffer, 0, len);
			}
		} finally {
			close(gis);
			close(fos);
		}
	}

	private static void close(Closeable io) {
		if (io != null) {
			try {
				io.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
			io = null;
		}
	}
}
